package xyz.zhouzhousag.utils;
/**
 * Description:
 * <p>
 * ClassName: DateUtils
 * date: 2021/3/17 10:27
 *
 * @author Yin.Liu
 * @version 1.0
 * @since JDK 1.8
 */

import sun.java2d.pipe.SpanShapeRenderer;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *@ClassName DateUtils
 *@Description TODO
 *@Author Yin.Liu8
 *@Date 2021/3/17 10:27
 *@Version 1.0
 */
public class DateUtils {

    /**
     * 日期转换成字符串
     * @param date
     * @param patt
     * @return
     */
    public static String dateToString(Date date,String patt){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(patt);
        return simpleDateFormat.format(date);
    }


    /**
     * 字符串转日期格式
     * @param date
     * @param patt
     * @return
     */
    public static Date stringToDate(String date,String patt){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(patt);
        try {
            return simpleDateFormat.parse(date);
        } catch (Exception e) {
            throw new RuntimeException("日期转换类异常：" + e);
        }
    }
}
